# -*- coding:utf-8 -*-
# @Author : yushen
# @Time : 2020-07-10 18:37
import requests
from common.config import getconf


def dayunying_login():
    '''获取大运营cookie'''
    url = 'http://c.rongyi.com/ryoms/j_spring_security_check'

    header = {
        "Content-Type": "application/x-www-form-urlencoded",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
    }
    data = {"j_username": "qa2018", "j_password": "ComeOn2020", "verifyCode": ""}
    r = requests.post(url=url, headers=header, data=data, allow_redirects=False)
    cookie = requests.utils.dict_from_cookiejar(r.cookies)

    return cookie['RYST']


def get_park_cookies(env, user, pw):
    """获取容易停车Cookise"""
    base_url = getconf(env, "rypark_url")
    url = base_url + "easypark-backend/parkUser/login"
    headers = {"content-type": "application/json;charset=UTF-8"}
    dic = {"account": user, "password": pw}
    # 提取cookies值
    cookie_jar = requests.post(url, headers=headers, json=dic).cookies
    cookie_dict = requests.utils.dict_from_cookiejar(cookie_jar)
    for k, v in cookie_dict.items():
        cookie = str(k + "=" + v)
        return cookie

def get_park_token(env, user, pw):
    """获取新容易停车商家后台token"""
    base_url = getconf(env, "zhongtai_url")
    url = base_url + "buorg/v1/session/login"
    headers = {"content-type": "application/json;charset=UTF-8","application":"cms"}
    dic = {"account": user, "password": pw}
    r = requests.post(url, json=dic, headers=headers)
    token = r.json()['token']
    return token
